package com.cssl.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cssl.pojo.Decruitment;
import com.cssl.serice.DecruitmentSerice;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;


@RestController
public class DecruitmentController {

    @Resource
    private DecruitmentSerice decruitment;

    //分页解聘查询
    @RequestMapping("/dequery")
    public IPage<Decruitment> dequery(String code,String date,Integer pageIndex, Integer pageSize){
      if (pageIndex ==null){
          pageIndex =1;
      }
        IPage<Decruitment> page;
      if (code ==""){
          page=decruitment.dquery(new Page<Decruitment>(pageIndex,pageSize),new QueryWrapper<Decruitment>()
                  .like(date !=null,"decruitmentDate",date).like(code !=null,"a.staff_id",code));
      }else {
          page=decruitment.dquery(new Page<Decruitment>(pageIndex,pageSize),new QueryWrapper<Decruitment>()
                  .like(date !=null,"decruitmentDate",date).eq(code !=null,"a.staff_id",code));
      }
        return  page;
    }


    //解聘的岗位的查询

   //解聘添加   把选择员工的值拿过来传到前端去
    @RequestMapping("/deinsert")
    public boolean deinsert(Decruitment d){

        return decruitment.saveOrUpdate(d);
    }

    //修改查询 单个查询
    @RequestMapping("/dss")
    public Decruitment dss(int id){
        return  decruitment.getById(id);
    };

    //删除 根据id删除
    @RequestMapping("/dsdelete")
    public boolean dsdelete(String... arr){

        return decruitment.removeBatchByIds(Arrays.asList(arr));
    }






    //离职统计
    @RequestMapping("/dequerya")
    public List<Decruitment> dequerya(String date){
         List<Decruitment> list=decruitment.dequerys(new QueryWrapper<Decruitment>() .like(date !=null,"decruitmentDate",date));
         return  list;
    }




}
